Sql: Retrieve Foreign Key information from the database#346
Merged
Conversation
Add non-key column foreign key
aaronburtle
reviewed
Apr 15, 2022
gledis69
reviewed
Apr 18, 2022
gledis69
reviewed
Apr 18, 2022
gledis69
reviewed
Apr 18, 2022
gledis69
approved these changes
Apr 18, 2022
gledis69
left a comment
Contributor
There was a problem hiding this comment.
Great addition! Had just a couple of question/suggestions.
aaronpowell
requested changes
Apr 19, 2022
aaronpowell
approved these changes
Apr 20, 2022
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What is the change?
At bootstrap, in addition to retrieving table's primary keys and column information, this change adds functionality to retrieve foreign key information
-- the table it references,
-- the referenced columns and
-- the columns from the referencing table.
Why is this change needed?
We need to know the foreign key information since this is useful to write the correct queries to perform joins in GraphQL.
How is this implemented?
SqlMetadataProvider::PopulateForeignKeyDefinitionAsync- takes in all the tables for which foreign key information is to be populated, invokes the methods to retrieve the information and fills in theForeignKeyDefinitionfor each table.SqlGraphQLFileMetadataProvidercalls this function at bootstrapBaseSqlQueryBuilder.For MySql, the foreign key query only needs the view
KEY_COLUMN_USAGE- added it toMySqlQueryBuilderMySqlHow is this tested?
sql-config.jsonand made sure existing tests don't regress.SqlMetadataProviderTest. To know what we expect, made suresql-config-test.jsonis updated.stocks_price_stocks_fkstocks_comics_fkRemarks
sql-config.jsonas compared tocosmos-config.jsonis theHttpVerbssection which can also be removed in favor of relying onsql-config-test.jsonfor testing until the developer config change is checked in.